package com.yzc.android.ui;

import android.support.test.espresso.action.ViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

import java.io.IOException;

import com.yzc.android.R;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Created by yzc on 16/5/4.
 */
@RunWith(AndroidJUnit4.class)
public class RecyclerViewActivityTestWithEspresso {
    protected MockWebServer mMockWebServer;

    @Rule
    public ActivityTestRule<RecyclerViewActivity> mActivityRule = new ActivityTestRule<>(
            RecyclerViewActivity.class);

    @Before
    public void setUp() throws Exception {
        mMockWebServer = new MockWebServer();
        try {
            mMockWebServer.start(Integer.parseInt("4000"));
        } catch (IOException e) {
            throw e;
        }
    }

    @After
    public void tearDown() throws Exception {
        mMockWebServer.shutdown();
    }

    @Test
    public void testThatDefaultBehaviorIsWorking() throws Exception {
        // https://github.com/square/okhttp/tree/master/mockwebserver
        mMockWebServer.enqueue(new MockResponse().setBody("stubs/rank_ok.json"));
        onView(withId(R.id.recycler_view)).perform(ViewActions.click());
    }
}